<?php

  session_start();

  if (!isset($_SESSION['playerId'])) {
  	//throw new Exception('You must be logged!');
	die('请先登陆');
	exit;
  }

  $allowed_page = true;

  function __autoload($className) {
    if (!isset($allowed_page)) { $allowed_page = true; }
	require_once("lib/config.php");
	require_once CLASS_PATH."{$className}.class.php";
  }

  if (!isset($_SESSION['engine'])) {
	$_SESSION['engine'] = new Engine();
  }
  	$playa=new Player();
	$playa->Load($_SESSION['playerId']);

  $myCharacters = $_SESSION['engine']->loadMyCharacters();

  function printChar($char, $key) {
    print("\n<input type=\"radio\" name=\"character\" value=\"".$char['cid']."\"> ".$char['charactername']."");
    print("\n<br>");
	return true;
  }

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link type="text/css" rel="stylesheet" href="../css/global.css">
  <link type="text/css" rel="stylesheet" href="../css/portal.css">
  <link type="text/css" rel="stylesheet" href="../css/select_character.css">
  <title>D5Power WebGame Engine - 用户中心</title>
</head>
<body>

<div id="main_top">
</div>

<div id="container_principal">

  <div id="textura_lateral_esquerda">

	<!-- #Menu -->
	<div class="menu">
	  <div class="menu_esquerda"></div>
	  <div class="menu_direita"></div>
	  <div class="menu_inferior"></div>
	  <div class="menu_superior"></div>

	  <p class="itens_menu">
	    <img border="0" src="../pictures/portal/menu_hover_icon.gif" align="top" width="16" height="17">
	    <b><a href="index.php">主页</a></b><br>
	
		<img border="0" src="../pictures/portal/menu_line.gif" width="122" height="5"><br>

	    <img border="0" src="../pictures/portal/menu_hover_icon.gif" align="top" width="16" height="17">
	    <b><a href="register.php">注册新帐户</a></b><br>

	    <img border="0" src="../pictures/portal/menu_line.gif" width="122" height="5"><br>
	  </p>
	</div>
	<!-- end #menu -->


    <div id="barra_lateral_esquerda">    </div>
  </div>
  <!-- fim do quadro textura lateral -->


	<!-- #main -->
    <div id="main" style="width:645px">
    	
		<p style="text-align: center;">欢迎回来 <?php print($playa->getUsername()); ?><br></p>

		<div class="form_header">
			<p><img style="vertical-align: middle;" src="../pictures/portal/header_left.gif">请选择您的角色：</p>
		</div>
		
		<div class="form_square">
          <div class="lateral_esquerda"></div>
		  <div class="lateral_direita"></div>
		  <div class="linha_inferior"></div>
		  <div class="linha_superior"></div>
		  <div style="padding: 10px;">
		
          <?php
                if (count($myCharacters) > 0) {
  					print("<form name=\"frm_char_login\" method=\"POST\" action=\"d5power.php\">");
					array_walk($myCharacters, 'printChar');
					print("\n<input type=\"hidden\" name=\"action\" value=\"enterGame\">");
    				print("\n<p style=\"text-align: center\"><input type=\"button\" onClick=\"submit();\" value=\"进入游戏\"></p>\n");
					print("\n</form>");
                }
				else {
					print("<p style=\"text-align: center; margin: 10px 10px 10px 10px;\">");
					print("您还没有创建角色<br>请点击 \"创建角色\" 按钮创建您的第一个角色");
					print("</p>");
				}
           ?>
		  </div>
		</div>
	  		
		<p style="text-align: center">
			<a href="create_character.php">
				<img src="../pictures/portal/button_create_char.png" style="border: solid 1px #996600">
			</a>
		</p>
    </div>
	<!-- end #main -->


    <div id="textura_lateral_direita">
      <div id="barra_lateral_direita">
      </div>
    </div>

</div>

</body>
</html>